#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Entry point for running the Flask application directly.
This file allows running the Flask app from PyCharm or command line
without using the 'flask run' command.
"""

import os
import sys

# Add the parent directory to the Python path so we can import 'sayhello'
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from sayhello import app, db

def init_db():
    """Initialize the database."""
    with app.app_context():
        db.create_all()
    print("Database initialized.")

if __name__ == '__main__':
    # Initialize the database if it doesn't exist
    if not os.path.exists(os.path.join(os.path.dirname(__file__), 'data.db')):
        init_db()
    
    # Run the Flask application
    app.run(
        host='127.0.0.1',
        port=5000,
        debug=True
    )